import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-03-20
 * Time: 21:21
 */
class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("hello");
        stringBuilder.append(" word");
        System.out.println(stringBuilder);
        StringBuffer stringBuffer = new StringBuffer("hello");//适用于多线程操作
        stringBuffer.append(" word");
        System.out.println(stringBuffer);
        String s = "hello";
        String s2 = s + " word";
        System.out.println(s2);//效率更慢，但不改变原来字符串
    }
    public static void main15(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("abcdefg");
        stringBuilder.insert(3,"666");
        System.out.println(stringBuilder);
    }
    public static void main14(String[] args) {
        String s = "    abb    cc     d   e    ";
        System.out.println(s);
        String s2 = s.trim();//去除字符串左右两边的空格
        System.out.println(s2);
    }
    public static void main13(String[] args) {
        String s = "abcdef";
        String s2 = s.substring(2,4);//从[2,4)截取字符串
        System.out.println(s2);
    }
    public static void main12(String[] args) {
        String s = "ab\\cd\\ef";
        String[] strings = s.split("\\\\");
        for (int i = 0; i < strings.length; i++) {
            System.out.print(strings[i] + " ");
        }
    }
    public static void main11(String[] args) {
        String s = "192.666.0.1";
        String[] strings = s.split("\\.");
        for (int i = 0; i < strings.length; i++) {
            System.out.print(strings[i] + " ");
        }
    }
    public static void main10(String[] args) {
        String s = "name=lyw&age=19";
        String[] strings = s.split("&");
        //String[] strings = s.split("%|=");
        for (int i = 0; i < strings.length; i++) {
           String[] strings1 = strings[i].split("=");
            for (int j = 0; j < strings1.length; j++) {
                System.out.println(strings1[j]);
            }
        }
    }
    public static void main9(String[] args) {
        String s = "ababcabcd";
        String tmp = s.replace('a','k');//将a全部替换为k
        System.out.println(tmp);
        tmp = s.replace("ab", "666");
        System.out.println(tmp);
        tmp = s.replaceFirst("ab","666");//只替换第一次出现的
        System.out.println(tmp);
    }
    public static void main8(String[] args) {
        String s = "hello";
        char[] array = s.toCharArray();//将字符串转化为数组
        for (int i = 0; i < array.length ; i++) {
            System.out.print(array[i] + " ");
        }

    }
    public static void main7(String[] args) {
        String s = "Hello";
        String s2 = s.toUpperCase();
        System.out.println(s2);
        String s3 = s.toLowerCase();
        System.out.println(s3);
    }
    public static void main6(String[] args) {
        String s1 = String.valueOf(1234);//转换字符串
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(false);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        String s4 = String.valueOf(new Student("lyw",19));
        System.out.println(s4);

        int date1 = Integer.parseInt("1234");
        Double date2 = Double.parseDouble("12.34");
        System.out.println(date1 + 1);
        System.out.println(date2 + 1);

    }
    public static void main5(String[] args) {
        String s = "ababcabcd";
        int index = s.lastIndexOf('a');//从后往前数下标
        System.out.println(index);
        index = s.lastIndexOf('a',4);
        System.out.println(index);
        index = s.lastIndexOf("ab",3);
        System.out.println(index);
    }
    public static void main4(String[] args) {
        String s1 = "hello";
        int index = s1.indexOf('l');//从前往后找到字符的下标，第一次出现的
        System.out.println(index);

        index = s1.indexOf('l',4);//从下标4开始找
        System.out.println(index);

        index = s1.indexOf("ll",1);
        System.out.println(index);
        char ch1 = s1.charAt(1);//获得字符串对应下标的字符
        System.out.println(ch1);

        System.out.println("=============");
        for (int i = 0; i < s1.length(); i++) {
            char ch2 = s1.charAt(i);
            System.out.println(ch2);
        }
        System.out.println("=============");

        int[] arr = { 1, 2, 3 , 4 ,5};
        System.out.println(arr.length);//求数组的长度
    }
    public static void main3(String[] args) {
        String s1 = "abcdef";
        String s2 = "aaaaaa";
        String s3 = "aaaaaaa";
        System.out.println(s1.compareTo(s2));
        System.out.println(s2.compareTo(s3));
    }
    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = s1;
        System.out.println(s1 == s2);
        System.out.println(s1 == s3);//比较的是地址，不是内容
        System.out.println(s2 == s3);
        System.out.println("===============");
        System.out.println(s1.equals(s2));
        System.out.println(s1.equals(s3));//比较的是内容
        System.out.println(s2.equals(s3));

    }
    public static void main1(String[] args) {
        String str = "hello";
        String str2 = new String("word");
        char[] arr = {'a' , 'b' , 'c' };
        String str3 = new String(arr);//数组转字符串
        System.out.println(str);
        System.out.println(str2);
        System.out.println(str3);
    }
}
